<?php
include dirname(dirname(dirname(__FILE__))).'/admin-verify.php';
include dirname(dirname(__FILE__))."/functions.php";
/**
 * $arr 0 为 user id 1 为pat id 2 为 pa id 3为period
 */
$msg="";
if (isset($_POST["val"])) {
	$val=$_POST["val"];
	$arr=explode(",", $val);
	$s_user_id=$arr[0];
	$pat_id=$arr[1];
	$pa_id=$arr[2];
	$period=$arr[3];
	$ret=applyListByPatId($pat_id, $period);
	if ($ret) {
		while ($row=mysql_fetch_array($ret)){
			if ($row["s_user_id"]==$s_user_id) {	
				
				$params=array('status'=>1);
				updateApply($params, $row["id"]);				
				
			}else{
				$params=array('status'=>2); 
			updateApply($params, $row["id"]);				
				
			}
		}
		$ret1=getPlaceApplyTableById($pat_id);
		$row1=mysql_fetch_array($ret1);
		$arr1=json_decode($row1["table_content"],true);
		$arr1[$period]=(int)$s_user_id;
		$arr1=json_encode($arr1);
		$params1=array("table_content"=>'"'.$arr1.'"');
		if(!updatePlaceApplyTable($params1, $pat_id)){
			$msg="error";
		}else {
			$msg="success";
		}

			
	}else {
		$msg="error";
	}
	echo json_encode($msg);
	
}
?>